<template>
  <div :id="id" :class="className" :style="{ height: height, width: width }" />
</template>

<script>
import echarts from "echarts";
import resize from "./mixins/resize";

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: "chart",
    },
    id: {
      type: String,
      default: "chart",
    },
    width: {
      type: String,
      default: "200px",
    },
    height: {
      type: String,
      default: "200px",
    },
  },
  data() {
    return {
      chart: null,
    };
  },
  created() {},
  mounted() {
    this.initChart();
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart() {
      let label = [
        "业务一部XX",
        "业务二部XX",
        "业务三部XX",
        "业务四部XX",
        "业务五部XX",
        "业务六部XX",
        "业务七部XX",
      ];
      let value = [233, 233, 200, 180, 199, 233, 210, 180];
      this.chart = echarts.init(document.getElementById(this.id));
      this.chart.setOption({
        backgroundColor: "#fff",
        grid: {
          top: "5%",
          left: "3%",
          right: "3%",
          bottom: "10%",
        },
        tooltip: {
          trigger: "axis",
          backgroundColor: "transparent", //标题背景色
          borderColor: "#fff", //边框颜色
          borderWidth: 0, //边框线宽
          padding: 5,
          borderRadius: 6,
          axisPointer: {
            lineStyle: {
              color: {
                type: "linear",
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: "rgba(255,255,255,0)", // 0% 处的颜色
                  },
                  {
                    offset: 0.5,
                    color: "rgba(255,255,255,1)", // 100% 处的颜色
                  },
                  {
                    offset: 1,
                    color: "rgba(255,255,255,0)", // 100% 处的颜色
                  },
                ],
                global: false, // 缺省为 false
              },
            },
          },
          formatter: function (params) {
            return `<div style="background:#fff;padding: 20px;border-radius: 6px;
box-shadow: 0px 0px 12px 0px rgba(14,23,38,0.1);">
                    <div style="display: flex; align-items: center;justify-content: space-around;
 padding-bottom: 15px;
                    margin-bottom: 15px;
                    border-bottom: 1px solid #ebedf2;">
                    <span
                    style="
                        width: 12px;
                        height: 12px;
                        background: #3091F2;
                        border-radius: 2px;
                        margin-right: 10px
                    "
                    ></span>
                    <i style="color: #8fa1c9">被套类</i>
                    <p style="font-weight: 800; margin-left: 40px;color:#111;flex: 1;text-align: right;">147000</p>
                    </div>
                    <div style="display: flex; align-items: center;justify-content: space-around;
 padding-bottom: 15px;
                    margin-bottom: 15px;
                    border-bottom: 1px solid #ebedf2;">
                    <span
                    style="
                        width: 12px;
                        height: 12px;
                        background: #3091f2;
                        border-radius: 2px;
                        margin-right: 10px
                    "
                    ></span>
                    <i style="color: #8fa1c9">床套类</i>
                    <p style="font-weight: 800; margin-left: 40px;color:#111;flex: 1;text-align: right;">147000</p>
                    </div>
                    <div style="display: flex; align-items: center;justify-content: space-around;
 padding-bottom: 15px;
                    margin-bottom: 15px;
                    border-bottom: 1px solid #ebedf2;">
                    <span
                    style="
                        width: 12px;
                        height: 12px;
                        background: #3091f2;
                        border-radius: 2px;
                        margin-right: 10px
                    "
                    ></span>
                    <i style="color: #8fa1c9">枕套类</i>
                    <p style="font-weight: 800; margin-left: 40px;color:#111">147000</p>
                    </div>
                    <div style="display: flex; align-items: center;">
                    <span
                    style="
                        width: 12px;
                        height: 12px;
                        background: linear-gradient(-90deg, #2945CB, #2A67E4, #3798FD);
                        border-radius: 2px;
                        margin-right: 10px
                    "
                    ></span>
                    <i style="color: #8fa1c9">总计</i>
                    <p style="font-weight: 800; margin-left: 40px;color:#111;flex: 1;text-align: right;">147000</p>
                    </div>
                </div>    
                `;
          },
        },
        xAxis: [
          {
            type: "category",
            boundaryGap: false,
            axisLabel: {
              formatter: "{value}",
              fontSize: 14,
              margin: 20,
              textStyle: {
                color: "#A5B2CC",
              },
            },
            axisLine: {
              lineStyle: {
                color: "#EBEDF2",
              },
            },
            splitLine: {
              show: false,
              lineStyle: {
                color: "#EBEDF2",
              },
            },
            axisTick: {
              show: false,
            },
            data: label,
          },
        ],
        yAxis: [
          {
            boundaryGap: false,
            type: "value",
            axisLabel: {
              textStyle: {
                color: "#A5B2CC",
              },
            },
            nameTextStyle: {
              color: "#fff",
              fontSize: 12,
              lineHeight: 40,
            },
            splitLine: {
              lineStyle: {
                color: "#EBEDF2",
              },
            },
            axisLine: {
              show: false,
              lineStyle: {
                color: "#283352",
              },
            },
            axisTick: {
              show: false,
            },
          },
        ],
        series: [
          {
            name: "报名",
            type: "line",
            smooth: false,
            showSymbol: true,
            symbolSize: 8,
            zlevel: 3,
            itemStyle: {
              color: "#19a3df",
              borderColor: "#1B84ED",
            },
            lineStyle: {
              normal: {
                width: 2,
                color: "#1B84ED",
              },
            },
            areaStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(
                  0,
                  0,
                  0,
                  1,
                  [
                    {
                      offset: 0,
                      color: "rgba(27, 132, 237,0.1)",
                    },
                    {
                      offset: 0.8,
                      color: "rgba(27, 132, 237,0)",
                    },
                  ],
                  false
                ),
              },
            },
            data: value,
          },
        ],
      });
    },
  },
};
</script>

<style scoped lang="less"></style>
